<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/actions/admin/AdminAction.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/actions/Response.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/model/Service/Service.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/const/Error.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/model/Service/ServiceFactory.php';

final class PostDeleteAction extends AdminAction {
	protected function execute(Response $response) {
		if(isset($_POST['identity'])) {
			$serviceFactory = new ServiceFactory();
			$service = $serviceFactory->getService('PostService');
			if(!$service->delete($_POST['identity'])) {
				$response->setError(Error::DELETE_POST_ERROR);
			}
		}
		if($response->getError() === null) {
			$response->setActionPath('/post/index.html');
		}
	}
}
?>